<?php

/**
 * Class Lib_Repair_Adapter_LianTong
 * 联通失联修复
 * 2020/11/06
{
 */
class Lib_Repair_Implement_ZaiRui extends Lib_Repair_Base_ZR
{
    private static $obj = null;

    /**
     * 单例获取
     * @return Lib_Repair_Implement_ZaiRui
     */
    public static function getInstance(){
        if (is_null(self::$obj)) {
            self::$obj = new self();
        }
        return self::$obj;
    }
    /**
     * 修复接口
     * @param $data
     * @return array
     */
    public function repair($data) {
        $post_data = $this->buildData($data);
        if(empty($post_data)){
            return $this->returnData(400,'empty post data');
        }
        //接口发送
        return $this->curlPost('/v1/api/repair/batch/repairData', $post_data);
    }

    /**
     * 获取修复结果接口
     * @param $data
     * @return array
     */
    public function getRepairResult($data) {
        $post_data = $this->buildData($data);
        if(empty($post_data)){
            return $this->returnData(400,'empty post data');
        }
        //接口发送
        return $this->curlGet('/v1/api/repair/batch/infoV', $post_data);
    }

    /**
     * 绑定虚拟小号接口
     * @param $data
     * @return array
     */
    public function binding($data) {
        $post_data = $this->buildData($data);

        if(empty($post_data)){
            Func_Log::write('curl',   'curl_end', json_encode($data).json_encode($post_data));
            return $this->returnData(400,'绑定中间号码参数有误！');
        }

        $resData =  $this->curlPost('/v1/api/repair/phone/binding', $post_data);
        if($resData['code'] == 200) {
            $resData['data']['pass'] = 'YiDong';
            Lib_Redis_String::setex("bind_".$resData['data']['telx'],3600,json_encode($resData['data']));
        }
        return $resData;
    }

    /**
     * 解绑虚拟小号接口
     * @param $data
     * @return array
     */
    public function unbinding($data) {
        $post_data = $this->buildData($data);
        if(empty($post_data)){
            Func_Log::write('curl',   'curl_end', json_encode($data).json_encode($post_data));
            return $this->returnData(400,'解绑中间号码参数有误！');
        }
        $resData =  $this->curlPost('/v1/api/repair/phone/unBinding', $post_data);
        if($resData['code'] == 200) {
            Lib_Redis_String::del("bind_" . $data['telx']);
        }
        return $resData;
    }


}